<?php

namespace app\controller\app\article;

use App\controller\app\AppBase;
use App\model\ArticleModel;
use support\Request;
use Webman\Http\Response;
use app\service\Route;

class Article extends AppBase
{
    public function beforeAction(){
        $rtn = parent::beforeAction();
        if($rtn instanceof Response){
            return $rtn;
        }
    }

    /**
     * description:内容列表
     * @Route(reqUrl="/app.article.lst",authCheck=false)
     * author:yangkelong
     * data:2022/8/25
     */
    public function lst(){
        if(input('cid',0)==0){
            $res['code'] = 0;
            $res['list'] = [];
            $res['count'] = 0;
            $res['totalPages'] = 0;
            return json($res);

        }
        $where=[];
        $where[]=['useable','=',1];
        $where[]=['article_class_id','=',input('cid')];
        $mchArticleObj = new ArticleModel([],$this->app_id);
        $res = $mchArticleObj->lst($where);
        return json($res);
    }

    /**
     * description:内容详情
     * @Route(reqUrl="/app.article.detail",authCheck=false)
     * author:yangkelong
     * data:2022/8/25
     */
    public function detail(){
        if(input('article_id',null)===null){
            return error(1,'内容ID不能为空');
        }
        $res = ArticleModel::where([['app_id','=',$this->app_id],['article_id','=',input('article_id')]])->find();
        return $res ? success($res) : error(1,"内容不存在");
    }
}